package qldc.pm.tiensu.service.impl;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

import qldc.pm.tiensu.model.BienBanBanGiaoHoSo;
import qldc.pm.tiensu.model.CongViecBanGiao;
import qldc.pm.tiensu.model.DoiTuongTienSu;
import qldc.pm.tiensu.model.KetQuaTrichLuc;
import qldc.pm.tiensu.model.LichSuXoaAnTich;
import qldc.pm.tiensu.model.PhieuThongTinVeNguoiCoTienSu;
import qldc.pm.tiensu.model.TEMP_DoiTuongTienSu;
import qldc.pm.tiensu.model.TEMP_PhieuThongTinVeNguoiCoTienSu;
import qldc.pm.tiensu.model.TEMP_TienSu;
import qldc.pm.tiensu.model.TangThu;
import qldc.pm.tiensu.model.TienSu;
import qldc.pm.tiensu.model.YeuCauTrichLuc;
import qldc.pm.tiensu.service.base.SaoLuuTienSuLocalServiceBaseImpl;
import qldc.pm.tiensu.utils.saoluudulieu.objects.BienBanBanGiaoHoSoJAXB;
import qldc.pm.tiensu.utils.saoluudulieu.objects.BienBanBanGiaoHoSoListJAXB;
import qldc.pm.tiensu.utils.saoluudulieu.objects.CongViecBanGiaoJAXB;
import qldc.pm.tiensu.utils.saoluudulieu.objects.CongViecBanGiaoListJAXB;
import qldc.pm.tiensu.utils.saoluudulieu.objects.DoiTuongTienSuJAXB;
import qldc.pm.tiensu.utils.saoluudulieu.objects.DoiTuongTienSuListJAXB;
import qldc.pm.tiensu.utils.saoluudulieu.objects.KetQuaTrichLucJAXB;
import qldc.pm.tiensu.utils.saoluudulieu.objects.KetQuaTrichLucListJAXB;
import qldc.pm.tiensu.utils.saoluudulieu.objects.LichSuXoaAnTichJAXB;
import qldc.pm.tiensu.utils.saoluudulieu.objects.LichSuXoaAnTichListJAXB;
import qldc.pm.tiensu.utils.saoluudulieu.objects.PhieuThongTinVeNguoiCoTienSuJAXB;
import qldc.pm.tiensu.utils.saoluudulieu.objects.PhieuThongTinVeNguoiCoTienSuListJAXB;
import qldc.pm.tiensu.utils.saoluudulieu.objects.TEMP_DoiTuongTienSuJAXB;
import qldc.pm.tiensu.utils.saoluudulieu.objects.TEMP_DoiTuongTienSuListJAXB;
import qldc.pm.tiensu.utils.saoluudulieu.objects.TEMP_PhieuThongTinVeNguoiCoTienSuJAXB;
import qldc.pm.tiensu.utils.saoluudulieu.objects.TEMP_PhieuThongTinVeNguoiCoTienSuListJAXB;
import qldc.pm.tiensu.utils.saoluudulieu.objects.TEMP_TienSuJAXB;
import qldc.pm.tiensu.utils.saoluudulieu.objects.TEMP_TienSuListJAXB;
import qldc.pm.tiensu.utils.saoluudulieu.objects.TangThuJAXB;
import qldc.pm.tiensu.utils.saoluudulieu.objects.TangThuListJAXB;
import qldc.pm.tiensu.utils.saoluudulieu.objects.TienSuJAXB;
import qldc.pm.tiensu.utils.saoluudulieu.objects.TienSuListJAXB;
import qldc.pm.tiensu.utils.saoluudulieu.objects.YeuCauTrichLucJAXB;
import qldc.pm.tiensu.utils.saoluudulieu.objects.YeuCauTrichLucListJAXB;
import qldc.pm.tiensu.utils.saoluuphuchoi.RootTienSuJAXB;
import qldc.pm.tiensu.utils.saoluuphuchoi.SaoLuuUtils;

import com.liferay.portal.kernel.exception.SystemException;

/**
 * The implementation of the sao luu tien su local service.
 *
 * <p>
 * All custom service methods should be put in this class. Whenever methods are added, rerun ServiceBuilder to copy their definitions into the {@link qldc.pm.tiensu.service.SaoLuuTienSuLocalService} interface.
 *
 * <p>
 * This is a local service. Methods of this service will not have security checks based on the propagated JAAS credentials because this service can only be accessed from within the same VM.
 * </p>
 *
 * @author Brian Wing Shun Chan
 * @see qldc.pm.tiensu.service.base.SaoLuuTienSuLocalServiceBaseImpl
 * @see qldc.pm.tiensu.service.SaoLuuTienSuLocalServiceUtil
 */
public class SaoLuuTienSuLocalServiceImpl
    extends SaoLuuTienSuLocalServiceBaseImpl {
	 public void saoLuuDuLieu(long userId, File xmlFile) throws JAXBException, SystemException{
			if(null != xmlFile){
				RootTienSuJAXB root = new RootTienSuJAXB();
				BienBanBanGiaoHoSoListJAXB BienBanBanGiaoHoSoListListJaxb = createDataBienBanBanGiaoHoSoList();			
				root.setBienBanBanGiaoHoSoList(BienBanBanGiaoHoSoListListJaxb);
				
				CongViecBanGiaoListJAXB CongViecBanGiaoList = createDataCongViecBanGiaoList();			
				root.setCongViecBanGiaoList(CongViecBanGiaoList);

				DoiTuongTienSuListJAXB DoiTuongTienSuList = createDataDoiTuongTienSuList();			
				root.setDoiTuongTienSuList(DoiTuongTienSuList);

				KetQuaTrichLucListJAXB KetQuaTrichLucList = createDataKetQuaTrichLucList();			
				root.setKetQuaTrichLucList(KetQuaTrichLucList);

				LichSuXoaAnTichListJAXB LichSuXoaAnTichList = createDataLichSuXoaAnTichList();			
				root.setLichSuXoaAnTichList(LichSuXoaAnTichList);

				PhieuThongTinVeNguoiCoTienSuListJAXB PhieuThongTinVeNguoiCoTienSuList = createDataPhieuThongTinVeNguoiCoTienSuList();			
				root.setPhieuThongTinVeNguoiCoTienSuList(PhieuThongTinVeNguoiCoTienSuList);

				TangThuListJAXB TangThuList = createDataTangThuList();			
				root.setTangThuList(TangThuList);


				TEMP_DoiTuongTienSuListJAXB TEMP_DoiTuongTienSuList = createDataTEMP_DoiTuongTienSuList();			
				root.setTEMP_DoiTuongTienSuList(TEMP_DoiTuongTienSuList);

				TEMP_PhieuThongTinVeNguoiCoTienSuListJAXB TEMP_PhieuThongTinVeNguoiCoTienSuList = createDataTEMP_PhieuThongTinVeNguoiCoTienSuList();			
				root.setTEMP_PhieuThongTinVeNguoiCoTienSuList(TEMP_PhieuThongTinVeNguoiCoTienSuList);

				TEMP_TienSuListJAXB TEMP_TienSuList = createDataTEMP_TienSuList();			
				root.setTEMP_TienSuList(TEMP_TienSuList);

				TienSuListJAXB TienSuList = createDataTienSuList();			
				root.setTienSuList(TienSuList);
				

				YeuCauTrichLucListJAXB YeuCauTrichLucList = createDataYeuCauTrichLucList();			
				root.setYeuCauTrichLucList(YeuCauTrichLucList);
				

				
				// create JAXB context and instantiate marshaller
			    JAXBContext context = JAXBContext.newInstance(RootTienSuJAXB.class);
			    Marshaller m = context.createMarshaller();
			    
			    // Format output: indent xml file
			    //m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

			    // Write to System.out
			    //m.marshal(root, System.out);

			    // Write to File
			    m.marshal(root, xmlFile);
			  
			} else {
				System.out.println("File is empty");
			}
	   }

	private YeuCauTrichLucListJAXB createDataYeuCauTrichLucList() throws SystemException {
		YeuCauTrichLucListJAXB reult = new  YeuCauTrichLucListJAXB();
		List<YeuCauTrichLuc>  YeuCauTrichLucList =  yeuCauTrichLucPersistence.findAll();
		List<YeuCauTrichLucJAXB> jaxbs = new ArrayList< YeuCauTrichLucJAXB>();
		for (YeuCauTrichLuc c :  YeuCauTrichLucList){
			 YeuCauTrichLucJAXB cn = SaoLuuUtils.convertFormYeuCauTrichLucToJAXB(c);
			jaxbs.add(cn);
		}
		reult.setYeuCauTrichLuc(jaxbs);
		return reult;
	}

	private TienSuListJAXB createDataTienSuList() throws SystemException {
		TienSuListJAXB reult = new  TienSuListJAXB();
		List<TienSu>  TienSuList =  tienSuPersistence.findAll();
		List<TienSuJAXB> jaxbs = new ArrayList< TienSuJAXB>();
		for (TienSu c :  TienSuList){
			 TienSuJAXB cn = SaoLuuUtils.convertFormTienSuToJAXB(c);
			jaxbs.add(cn);
		}
		reult.setTienSu(jaxbs);
		return reult;
	}

	private TEMP_TienSuListJAXB createDataTEMP_TienSuList() throws SystemException {
		TEMP_TienSuListJAXB reult = new  TEMP_TienSuListJAXB();
		List<TEMP_TienSu>  TEMP_TienSuList =  temp_TienSuPersistence.findAll();
		List<TEMP_TienSuJAXB> jaxbs = new ArrayList< TEMP_TienSuJAXB>();
		for (TEMP_TienSu c :  TEMP_TienSuList){
			 TEMP_TienSuJAXB cn = SaoLuuUtils.convertFormTEMP_TienSuToJAXB(c);
			jaxbs.add(cn);
		}
		reult.setTEMP_TienSu(jaxbs);
		return reult;
	}

	private TEMP_PhieuThongTinVeNguoiCoTienSuListJAXB createDataTEMP_PhieuThongTinVeNguoiCoTienSuList() throws SystemException {
		TEMP_PhieuThongTinVeNguoiCoTienSuListJAXB reult = new  TEMP_PhieuThongTinVeNguoiCoTienSuListJAXB();
		List<TEMP_PhieuThongTinVeNguoiCoTienSu>  TEMP_PhieuThongTinVeNguoiCoTienSuList =  temp_PhieuThongTinVeNguoiCoTienSuPersistence.findAll();
		List<TEMP_PhieuThongTinVeNguoiCoTienSuJAXB> jaxbs = new ArrayList< TEMP_PhieuThongTinVeNguoiCoTienSuJAXB>();
		for (TEMP_PhieuThongTinVeNguoiCoTienSu c :  TEMP_PhieuThongTinVeNguoiCoTienSuList){
			 TEMP_PhieuThongTinVeNguoiCoTienSuJAXB cn = SaoLuuUtils.convertFormTEMP_PhieuThongTinVeNguoiCoTienSuToJAXB(c);
			jaxbs.add(cn);
		}
		reult.setTEMP_PhieuThongTinVeNguoiCoTienSu(jaxbs);
		return reult;
	}

	private TEMP_DoiTuongTienSuListJAXB createDataTEMP_DoiTuongTienSuList() throws SystemException {
		TEMP_DoiTuongTienSuListJAXB reult = new  TEMP_DoiTuongTienSuListJAXB();
		List<TEMP_DoiTuongTienSu>  TEMP_DoiTuongTienSuList =  temp_DoiTuongTienSuPersistence.findAll();
		List<TEMP_DoiTuongTienSuJAXB> jaxbs = new ArrayList< TEMP_DoiTuongTienSuJAXB>();
		for (TEMP_DoiTuongTienSu c :  TEMP_DoiTuongTienSuList){
			 TEMP_DoiTuongTienSuJAXB cn = SaoLuuUtils.convertFormTEMP_DoiTuongTienSuToJAXB(c);
			jaxbs.add(cn);
		}
		reult.setTEMP_DoiTuongTienSu(jaxbs);
		return reult;
	}

	private TangThuListJAXB createDataTangThuList() throws SystemException {
		 TangThuListJAXB reult = new  TangThuListJAXB();
			List<TangThu>  TangThuList =  tangThuPersistence.findAll();
			List<TangThuJAXB> jaxbs = new ArrayList< TangThuJAXB>();
			for (TangThu c :  TangThuList){
				 TangThuJAXB cn = SaoLuuUtils.convertFormTangThuToJAXB(c);
				jaxbs.add(cn);
			}
			reult.setTangThu(jaxbs);
			return reult;
	}

	private PhieuThongTinVeNguoiCoTienSuListJAXB createDataPhieuThongTinVeNguoiCoTienSuList() throws SystemException {
		 PhieuThongTinVeNguoiCoTienSuListJAXB reult = new  PhieuThongTinVeNguoiCoTienSuListJAXB();
			List<PhieuThongTinVeNguoiCoTienSu>  PhieuThongTinVeNguoiCoTienSuList =  phieuThongTinVeNguoiCoTienSuPersistence.findAll();
			List<PhieuThongTinVeNguoiCoTienSuJAXB> jaxbs = new ArrayList< PhieuThongTinVeNguoiCoTienSuJAXB>();
			for (PhieuThongTinVeNguoiCoTienSu c :  PhieuThongTinVeNguoiCoTienSuList){
				 PhieuThongTinVeNguoiCoTienSuJAXB cn = SaoLuuUtils.convertFormPhieuThongTinVeNguoiCoTienSuToJAXB(c);
				jaxbs.add(cn);
			}
			reult.setPhieuThongTinVeNguoiCoTienSu(jaxbs);
			return reult;
	}

	private LichSuXoaAnTichListJAXB createDataLichSuXoaAnTichList() throws SystemException {
		 LichSuXoaAnTichListJAXB reult = new  LichSuXoaAnTichListJAXB();
			List<LichSuXoaAnTich>  LichSuXoaAnTichList =  lichSuXoaAnTichPersistence.findAll();
			List<LichSuXoaAnTichJAXB> jaxbs = new ArrayList< LichSuXoaAnTichJAXB>();
			for (LichSuXoaAnTich c :  LichSuXoaAnTichList){
				 LichSuXoaAnTichJAXB cn = SaoLuuUtils.convertFormLichSuXoaAnTichToJAXB(c);
				jaxbs.add(cn);
			}
			reult.setLichSuXoaAnTich(jaxbs);
			return reult;
	}

	private KetQuaTrichLucListJAXB createDataKetQuaTrichLucList() throws SystemException {
		 KetQuaTrichLucListJAXB reult = new  KetQuaTrichLucListJAXB();
		List<KetQuaTrichLuc>  KetQuaTrichLucList =  ketQuaTrichLucPersistence.findAll();
		List<KetQuaTrichLucJAXB> jaxbs = new ArrayList< KetQuaTrichLucJAXB>();
		for (KetQuaTrichLuc c :  KetQuaTrichLucList){
			 KetQuaTrichLucJAXB cn = SaoLuuUtils.convertFormKetQuaTrichLucToJAXB(c);
			jaxbs.add(cn);
		}
		reult.setKetQuaTrichLuc(jaxbs);
		return reult;
	}

	private DoiTuongTienSuListJAXB createDataDoiTuongTienSuList() throws SystemException {
		// TODO Auto-generated method stub
		DoiTuongTienSuListJAXB reult = new DoiTuongTienSuListJAXB();
		List<DoiTuongTienSu> DoiTuongTienSuList = doiTuongTienSuPersistence.findAll();
		List<DoiTuongTienSuJAXB> jaxbs = new ArrayList<DoiTuongTienSuJAXB>();
		for (DoiTuongTienSu c : DoiTuongTienSuList){
			DoiTuongTienSuJAXB cn = SaoLuuUtils.convertFormDoiTuongTienSuToJAXB(c);
			jaxbs.add(cn);
		}
		reult.setDoiTuongTienSu(jaxbs);
		return reult;
	}

	private CongViecBanGiaoListJAXB createDataCongViecBanGiaoList() throws SystemException {
		// TODO Auto-generated method stub
		CongViecBanGiaoListJAXB reult = new CongViecBanGiaoListJAXB();
		List<CongViecBanGiao> CongViecBanGiaoList = congViecBanGiaoPersistence.findAll();
		List<CongViecBanGiaoJAXB> jaxbs = new ArrayList<CongViecBanGiaoJAXB>();
		for (CongViecBanGiao c : CongViecBanGiaoList){
			CongViecBanGiaoJAXB cn = SaoLuuUtils.convertFormCongViecBanGiaoToJAXB(c);
			jaxbs.add(cn);
		}
		reult.setCongViecBanGiao(jaxbs);
		return reult;
	}

	private BienBanBanGiaoHoSoListJAXB createDataBienBanBanGiaoHoSoList() throws SystemException {
		BienBanBanGiaoHoSoListJAXB reult = new BienBanBanGiaoHoSoListJAXB();
		List<BienBanBanGiaoHoSo> BienBanBanGiaoHoSoList = bienBanBanGiaoHoSoPersistence.findAll();
		List<BienBanBanGiaoHoSoJAXB> jaxbs = new ArrayList<BienBanBanGiaoHoSoJAXB>();
		for (BienBanBanGiaoHoSo c : BienBanBanGiaoHoSoList){
			BienBanBanGiaoHoSoJAXB cn = SaoLuuUtils.convertFormBienBanBanGiaoHoSoToJAXB(c);
			jaxbs.add(cn);
		}
		reult.setBienBanBanGiaoHoSo(jaxbs);
		return reult;
	}

}
